//
//  AboutViewController.m
//  NavBar
//
//  Created by MaartenG on 01-08-09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "AboutViewController.h"


@implementation AboutViewController



#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
	self.title = [[NSString alloc] initWithString:@"About"];
	
	UIBarButtonItem *cancelBtn = [[UIBarButtonItem alloc] initWithTitle:@"Dismiss" style:UIBarButtonSystemItemCancel
																 target:self action:@selector(dissmissView:)];	
	self.navigationItem.rightBarButtonItem = cancelBtn;
	
	UIView *prefView = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
	prefView.backgroundColor = UIColorFromRGB(0x003800);
	
	self.view = prefView;
	
	UILabel *aboutusLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,10,200,15)]
	 autorelease];
	aboutusLabel.backgroundColor = UIColorFromRGB(0x003800);
	aboutusLabel.textColor = [UIColor whiteColor];
	aboutusLabel.font = [UIFont boldSystemFontOfSize:15];
	aboutusLabel.text = [[NSString alloc] initWithString:@"About This Application:"];	
	
	UILabel *explainLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,30,300,110)]
	 autorelease];
	explainLabel.backgroundColor = UIColorFromRGB(0x003800);
	explainLabel.textColor = UIColorFromRGB(0xCCCCCC);
	explainLabel.font = [UIFont boldSystemFontOfSize:12];
	explainLabel.numberOfLines = 0;
	explainLabel.text = [[NSString alloc] initWithString:@"Application by Thiago Escudeiro Craveiro and Maarten Goldstein.\n\nThe creators of this application are not associated with any of the running game servers or any of the creators and modders of the game server code."];	
	
	UILabel *aboutthemLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,140,200,15)]
	 autorelease];
	aboutthemLabel.backgroundColor = UIColorFromRGB(0x003800);
	aboutthemLabel.textColor = [UIColor whiteColor];
	aboutthemLabel.font = [UIFont boldSystemFontOfSize:15];
	aboutthemLabel.text = [[NSString alloc] initWithString:@"About The Game:"];	
	
	UILabel *copyrightLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,160,300,150)]
	 autorelease];
	copyrightLabel.backgroundColor = UIColorFromRGB(0x003800);
	copyrightLabel.textColor = UIColorFromRGB(0xCCCCCC);
	copyrightLabel.font = [UIFont boldSystemFontOfSize:12];
	copyrightLabel.numberOfLines = 0;
	copyrightLabel.text = [[NSString alloc] initWithString:@"The Legend Of The Green Dragon game server source code is licensed under a Creative Commons License. Game art including logos released into the public domain.\n\nGame Design and Code: Copyright (c)  2002-2009, Eric Stevens, JT Traub and the DragonPrime Development Team\nJade Template (c) Josh Canning 2004 of HFS."];	
	
	
	UILabel *feedbackLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,315,200,15)]
	 autorelease];
	feedbackLabel.backgroundColor = UIColorFromRGB(0x003800);
	feedbackLabel.textColor = [UIColor whiteColor];
	feedbackLabel.font = [UIFont boldSystemFontOfSize:15];
	feedbackLabel.text = [[NSString alloc] initWithString:@"Feedback:"];		
	

	UILabel *siteLabel =
	[[[UILabel alloc]
	  initWithFrame:
	  CGRectMake(10,330,300,50)]
	 autorelease];
	siteLabel.backgroundColor = UIColorFromRGB(0x003800);
	siteLabel.textColor = UIColorFromRGB(0xCCCCCC);
	siteLabel.font = [UIFont boldSystemFontOfSize:12];
	siteLabel.numberOfLines = 0;
	siteLabel.text = [[NSString alloc] initWithString:@"For bug reporting or general application feedback, please head to our website"];	
	
	UIButton *submitButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
	[submitButton setTitle:@"Open Site" forState:UIControlStateNormal];
	[submitButton setTitleColor:UIColorFromRGB(0x000000) forState:UIControlStateNormal];
	submitButton.frame = CGRectMake( 10, 380, 300, 30);	
	
	[submitButton addTarget:self action:@selector(askToOpenSafari) forControlEvents:UIControlEventTouchUpInside];
	
	[self.view addSubview:explainLabel];
	[self.view addSubview:aboutusLabel];
	[self.view addSubview:aboutthemLabel];
	[self.view addSubview:copyrightLabel];	
	[self.view addSubview:feedbackLabel];
	[self.view addSubview:siteLabel];
	[self.view addSubview:submitButton];
	
}

- (void)dissmissView:(id) sender {
	[self dismissModalViewControllerAnimated:YES];
}	

-(void)askToOpenSafari {
	// Open an alertview alerting the user to the fact that Safari will open. User can then cancel or proceed.
	NSString *alertText = [[NSString alloc] initWithString:@"This will open Safari"];
	UIAlertView *alert = [ [UIAlertView alloc] initWithTitle:@"External Link" message:alertText delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Proceed", nil];
	[alert show];
	[alert release];
	[alertText release];
}

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
	if ( buttonIndex == 0) { }
	else {
		[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://lotgd.maartengoldstein.com/"]];
	}	
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
